package com.gite.nouette.admin.implementation.view;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import com.gite.nouette.admin.contract.controller.ICModule;
import com.gite.nouette.admin.contract.view.IVCommand;
import com.gite.nouette.admin.contract.view.IVModule;
import com.smartgwt.client.types.HeaderControls;
import com.smartgwt.client.widgets.layout.Portlet;

public abstract class AbstractVModule<C extends ICModule<?, ?>> extends Portlet implements IVModule<C> {
	private C c;

	public AbstractVModule(IVCommand<?>... vCommands) {
		setHeaderCommands(vCommands);
	}

	@Override
	public String getName() {
		return getTitle();
	}

	@Override
	public void setName(String name) {
		setTitle(name);
	}

	@Override
	public C getC() {
		return c;
	}

	@Override
	public void setC(C c) {
		this.c = c;
	}

	private void setHeaderCommands(IVCommand<?>... vCommands) {
		List<Object> controls = new ArrayList<Object>();
		controls.add(HeaderControls.MINIMIZE_BUTTON);
		controls.add(HeaderControls.HEADER_LABEL);
		controls.addAll(Arrays.asList(vCommands));
		setHeaderControls(controls.toArray());
	}
}
